import { CrudOptions, AddReq, DelReq, EditReq, dict, CrudExpose, UserPageQuery, CreateCrudOptionsRet} from '@fast-crud/fast-crud';
import _ from 'lodash-es';
import * as api from './api';
import { request } from '/@/utils/service';
import {auth} from "/@/utils/authFunction";
import { downloadFile } from '/@/utils/service';

//此处为crudOptions配置
export default function ({ crudExpose}: { crudExpose: CrudExpose}): CreateCrudOptionsRet {
	const pageRequest = async (query: any) => {
		return await api.GetList(query);
	};
	const editRequest = async ({ form, row }: EditReq) => {
		if (row.id) {  
			form.id = row.id;
		}
		return await api.UpdateObj(form);
	};
	const delRequest = async ({ row }: DelReq) => {
		return await api.DelObj(row.id);
	};
	const addRequest = async ({ form }: AddReq) => {
		return await api.AddObj(form);
	};

    const exportRequest = async (query: UserPageQuery) => {
		return await api.exportData(query)
	};

	return {
		crudOptions: {
			request: {
				pageRequest,
				addRequest,
				editRequest,
				delRequest,
			},
			toolbar:{
				show:false,
			},
			actionbar: {
				show: false,				
			},
			search:{
				show: false,
			},
            rowHandle: {
				align: 'center',
                //固定右侧
                fixed: 'right',
                width: 200,
                buttons: {
                   download: {
						text:'下载',
						icon: "line-md:download-loop",
						click:(context)=>{							
							downloadFile({url:context.row.path});
						}
				   },
				   view:{
					show:false
				   },
				   remove:{
					show:false
				   },
				   edit:{
					show:false
				   }
                },
            },
			table: {
				rowKey: "id", //设置你的主键id， 默认rowKey=id				
			},
			columns: {
				_index: {
                    title: '#',
                    form: {show: false},
                    column: {
                        type: 'index',
                        align: 'center',
                        width: '70px',
                        columnSetDisabled: true, //禁止在列设置中选择
                    },
                },
				id: {
					title: "ID",
					key: "id",
					type: "text",					
					column: {
					  width: 0,
					  show:false,
					},
					form: {
					  show: false
					}
				},			
                name: {
					title: '导出标题',
					type: 'text',
					// type: 'number',
					search: { show: false },
					column: {
						minWidth: 120,
						sortable: 'custom',
					},					
				},
				create_datetime:{
					title:'提交时间',
					type: 'text',
					search: { show: false },
					column: {
						minWidth: 120,
						sortable: 'custom',
					},			
				},
				update_datetime:{
					title:'完成时间',
					type: 'text',
					search: { show: false },
					column: {
						minWidth: 120,
						sortable: 'custom',
					},			
				},                
				description:{
					title:'描述或原因',
					type: 'text',
					search: { show: false },
					column: {
						minWidth: 160,
						sortable: 'custom',
					},			
				}
			},
		},
	};
};